package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.DTO.ProductBO;
import com.ruoyi.common.core.domain.DTO.ProductSaveBO;
import com.ruoyi.common.core.domain.entity.Products;
import com.ruoyi.framework.web.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/product")
public class ProductController extends BaseController {
    @Autowired
    private ProductService productService;

    /**
     * 新增商品
     * @param productSaveBO
     * @return
     */
    @PostMapping("/save")
    public AjaxResult save(@RequestBody ProductSaveBO productSaveBO) {
        productService.insertProduct(productSaveBO);
        return success();
    }

    /**
     * 修改商品
     * @param products
     * @return
     */
    @PostMapping("/update")
    public AjaxResult update(@RequestBody Products products) {
        productService.updateProduct(products);
        return success();
    }

    /**
     * 商品列表
     * @param productBO
     * @return
     */
    @PostMapping("/list")
    public AjaxResult list(@RequestBody ProductBO productBO) {
        return success(productService.selectProductList(productBO));
    }
}
